package cn.tedu.psychology.controller;

import cn.tedu.psychology.pojo.dto.QuestionAnswerAddNewDTO;
import cn.tedu.psychology.pojo.vo.QuestionAnswerListItemVO;
import cn.tedu.psychology.pojo.vo.QuestionAnswerStandardVO;
import cn.tedu.psychology.service.IQuestionAnswerService;
import cn.tedu.psychology.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "问题回答模块")
@RestController
@RequestMapping("/question-answers")
public class QuestionAnswerController {

    @Autowired
    private IQuestionAnswerService questionAnswerService;

    @ApiOperation("回答问题")
    @PostMapping("/add-new")
    public JsonResult addNew(QuestionAnswerAddNewDTO questionAnswerAddNewDTO) {
        questionAnswerService.addNew(questionAnswerAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("回答问题详情")
    @GetMapping("/{userId:[0-9]+}")
    public JsonResult getStandardByUserId(@PathVariable Long userId) {
        QuestionAnswerStandardVO questionAnswerStandardVO = questionAnswerService.getStandardByUserId(userId);
        return JsonResult.ok(questionAnswerStandardVO);
    }

    @ApiOperation("回答问题列表")
    @GetMapping("/{questionId:[0-9]+}/list")
    public JsonResult list(@PathVariable Long questionId) {
        List<QuestionAnswerListItemVO> list = questionAnswerService.listByQuestionId(questionId);
        return JsonResult.ok(list);
    }

}
